import A1 from '@/views/login/a1.vue'
import A2 from '@/views/login/a2.vue'
import A3 from '@/views/login/a3.vue'
import A4 from '@/views/login/a4.vue'
import Dl from '@/views/login/dl.vue'
import Login from '@/views/login/login.vue'
import Ss from '@/views/login/ss.vue'
import Xq from '@/views/login/xq.vue'
import Zc from '@/views/login/zc.vue'
import { createRouter, createWebHistory } from 'vue-router'

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/login',
      component: Login,
      children: [
        {
          path: 'a1',
          component: A1,
        },
        {
          path: 'a2',
          component: A2,
        },
        {
          path: 'a3',
          component: A3,
        },
        {
          path: 'a4',
          component: A4,
        }
      ]
    },
    {
      path: '/zc',
      component: Zc,
    },
    {
      path: '/dl',
      component: Dl,
    },
    {
      path: '/ss',
      component: Ss,
    },
    {
      path: '/xq/:goods_id',
      component: Xq,
    },
  ],
})
router.beforeEach((to, from, next) => {
  if (to.fullPath == '/login/a3' || to.fullPath == '/login/a4') {
    let token = localStorage.getItem('token')
    if (token) {
      next()
    } else {
      next('/zc')
    }
  } else {
    next()
  }
})
export default router
